package thread;

//不同对象，执行同一个方法，排队
public class SyncDemo3  {
    public static void main(String[] args) {
        Boo b1=new Boo();
        Boo b2=new Boo();
        Thread t1=new Thread(){
            @Override
            public void run() {
                //Boo.dosome();
                b1.dosome();
            }
        };
        Thread t2=new Thread(){
            @Override
            public void run() {
               // Boo.dosome();
                b2.dosome();
            }
        };
        t1.start();
        t2.start();
    }
}
class Boo{
    public synchronized  void dosome(){
        Thread t=Thread.currentThread();
        synchronized (Boo.class){
            try {

                System.out.println(t.getName()+":执行");
                Thread.sleep(5000);
                t.wait(5000);

            } catch (InterruptedException | IllegalMonitorStateException e) {
                e.printStackTrace();
            }finally {
                System.out.println(t.getName()+":完毕");
            }
        }

    }
}